﻿using System;
using System.Text;
using System.Windows.Forms;

namespace RegexSharp
{
    public partial class Form_Error : Form
    {
        private string _runMode = string.Empty;
        public string RunMode
        {
            get { return _runMode; }
            set { _runMode = value; }
        }

        private string _content = string.Empty;
        public string Content
        {
            get { return _content; }
            set { _content = value; }
        }

        private string _regexText = string.Empty;
        public string RegexText
        {
            get { return _regexText; }
            set { _regexText = value; }
        }

        private string _replacement = string.Empty;
        public string Replacement
        {
            get { return _replacement; }
            set { _replacement = value; }
        }

        private string _matchEvaluator = string.Empty;
        public string MatchEvaluator
        {
            get { return _matchEvaluator; }
            set { _matchEvaluator = value; }
        }

        private Exception _unhandledException;
        public Exception UnhandledException
        {
            get { return _unhandledException; }
            set { _unhandledException = value; }
        }

        public Form_Error()
        {
            InitializeComponent();
        }

        private void GenerateErrorMessage()
        {
            if (_unhandledException != null)
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendLine("Please send this message to angieduan@gmail.com, Thanks!");
                sb.AppendLine();
                sb.AppendLine("=== Mode Start ===");
                sb.AppendLine(_runMode);
                sb.AppendLine("=== Mode End ===");
                sb.AppendLine();
                sb.AppendLine("=== Content Start ===");
                sb.AppendLine(_content);
                sb.AppendLine("=== Content End ===");
                sb.AppendLine();
                sb.AppendLine("=== RegexText Start ===");
                sb.AppendLine(_regexText);
                sb.AppendLine("=== RegexText End ===");
                sb.AppendLine();
                sb.AppendLine("=== Replacement Start ===");
                sb.AppendLine(_replacement);
                sb.AppendLine("=== Replacement End ===");
                sb.AppendLine();
                sb.AppendLine("=== MatchEvaluator Start ===");
                sb.AppendLine(_matchEvaluator);
                sb.AppendLine("=== MatchEvaluator End ===");
                sb.AppendLine();
                sb.AppendLine("=== Exception Start ===");
                sb.AppendLine(_unhandledException.ToString());
                sb.AppendLine("=== Exception End ===");

                textBox_ErrorMessage.Text = sb.ToString();
            }
        }

        private void Form_Error_Load(object sender, EventArgs e)
        {
            GenerateErrorMessage();
        }

        private void button_OK_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
